package middleware

import (
	"GOPAAS/internal/utils"
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

func Cors() gin.HandlerFunc {
	return func(c *gin.Context) {
		method := c.Request.Method //请求方法
		//放行所有OPTIONS方法
		if strings.ToLower(method) == "options" {
			utils.SetCorsHeader(c)
			c.JSON(http.StatusOK, "Options Request!")
			c.Abort()
			return
		}
		return
	}
}
